﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HeroSkills : MonoBehaviour
{
    [SerializeField] private Transform SkillSpawnPosition;

    private ObjectPooler _pooler;
    private Hero _hero;
    private Skill _currentSkillLoaded;

    private void Start()
    {
        _pooler = GetComponent<ObjectPooler>();
        _hero = GetComponent<Hero>();
        //LoadSkill();
    }

    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.G))
        {
            LoadSkill();
        }

        //if (IsHeroEmpty())
        //{
        //    LoadSkill();
        //}

        if(_hero.CurrentMonsterTarget != null && _currentSkillLoaded != null)
        {
            _currentSkillLoaded.SetMonster(_hero.CurrentMonsterTarget);
        }
    }

    public void LoadSkill()
    {
        GameObject newInstance = _pooler.GetInstanceFromPool();
        newInstance.transform.localPosition = SkillSpawnPosition.position;
        
        _currentSkillLoaded = newInstance.GetComponent<Skill>();
       
        newInstance.SetActive(true);
    }

    public void ResetHeroSkill()
    {
        _currentSkillLoaded = null;
    }
}
